package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button mButtonLlay;
    private Button mButtonRlay;
    private Button mButtonTextView;
    private Button mButtonBtn;
    private Button mButtonEdt;
    private Button mButtonRb;
    private Button mButtonCb;
    private Button mButtonjpg;
    private Button mButtonscroll;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);//调用父类方法
        setContentView(R.layout.activity_main);//加载布局文件

        mButtonLlay = findViewById(R.id.btn_llay);
        mButtonRlay = findViewById(R.id.btn_rlay);
        mButtonTextView = findViewById(R.id.btn_tv);
        mButtonBtn = findViewById(R.id.btn_btn);
        mButtonEdt = findViewById(R.id.edt_btn);
        mButtonRb = findViewById(R.id.rb_btn);
        mButtonCb = findViewById(R.id.cb_btn);
        mButtonjpg = findViewById(R.id.jpgv_btn);
        mButtonscroll = findViewById(R.id.scroll_btn);
        setListeners();
    }

    private void setListeners(){
        OnClick toclick = new OnClick();
        mButtonLlay.setOnClickListener(toclick);
        mButtonRlay.setOnClickListener(toclick);
        mButtonTextView.setOnClickListener(toclick);
        mButtonBtn.setOnClickListener(toclick);
        mButtonEdt.setOnClickListener(toclick);
        mButtonRb.setOnClickListener(toclick);
        mButtonCb.setOnClickListener(toclick);
        mButtonjpg.setOnClickListener(toclick);
        mButtonscroll.setOnClickListener(toclick);
    }

    private class OnClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent intent = null;
            switch (v.getId()){
                case R.id.btn_llay:
                    intent = new Intent(MainActivity.this, LinearLayoutActivity.class);
                    break;
                case R.id.btn_rlay:
                    intent = new Intent(MainActivity.this, RelativeLayoutActivity.class);
                    break;
                case R.id.btn_tv:
                    intent = new Intent(MainActivity.this,TextViewActivity.class);
                    break;
                case R.id.btn_btn:
                    intent = new Intent(MainActivity.this,ButtonActivity.class);
                    break;
                case R.id.edt_btn:
                    intent = new Intent(MainActivity.this,EditTextActivity.class);
                    break;
                case R.id.rb_btn:
                    intent = new Intent(MainActivity.this, RadioButtonActivity.class);
                    break;
                case R.id.cb_btn:
                    intent = new Intent(MainActivity.this, CheckBoxActivity.class);
                    break;
                case R.id.jpgv_btn:
                    intent = new Intent(MainActivity.this, ImageViewActivity.class);
                    break;
                case R.id.scroll_btn:
                    intent = new Intent(MainActivity.this, ScrollViewActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }
}